<template>
    <div class="table_box">
        <TableCard title="游客投诉管理" :table_data="table_data" :search_box_visibale="false" :table_item="table_item"
            :user="'complaints'" :add_btn_visible="false" @SizeChange="SizeChange" @currentPage="currentPage"
            @is_add_dialog_visible="is_add_dialog_visible" @row_id="row_id" @filter_three="filter_three" :total="total"
            :loading="loading" />
    </div>
</template>

<script>
import TableCard from '@/components/reusable_components/table_card.vue'
export default {
    components: {
        TableCard,
    },

    data() {
        return {
            table_item: [
                // { key: 'index', value: '序号', default: '' },
                { key: 'title', value: '标题', default: '' },
                { key: 'content', width: '250', value: '内容', default: '' },
                { key: 'enterprise', value: '投诉对象', default: '' },
                { key: 'sender', value: '发送者', default: '' },
                { key: 'send_date', value: '发送时间', default: '' },
                { key: 'if_coped', value: '状态', default: '' },
            ],
            table_data: [],
            pageSize: 10,
            current_page: 1,
            add_dialog_visible: false,
            delete_row: 0,
            row_index: 0,
            // 新增
            add_form: {
            },
            total: 0,
            loading: true

        }
    },

    mounted() {
        this.SizeChange(this.pageSize);
        this.currentPage(this.current_page);
        this.get_complaints()
    },

    methods: {

        // 根据子组件传来的信息，显示/关闭对话框
        is_add_dialog_visible(val) {
            this.add_dialog_visible = val
        },


        async get_complaints() {
            this.loading = true
            try {
                const res = await this.$http.post('/findAllComplaint', {
                    pageNum: this.current_page,
                    pageSize: this.pageSize
                });

                this.total = res.data.data.size
                this.table_data = res.data.data.information
                this.loading = false
            } catch (error) { }
        },

        // 获取子组件传来的数据，当分页数据变化时，发送请求
        async SizeChange(size) {
            this.pageSize = size;
            this.get_complaints()
        },

        async currentPage(page) {
            this.current_page = page;
            this.get_complaints()
        },

        async filter_three(val) {
            let url = ''
            console.log(val)
            switch (val) {
                case '不限':
                    url = '/findAllApplication'
                    this.get_complaints()
                    return
                case '未处理':
                    url = '/findComplaintUnCoped'
                    break
                case '已处理':
                    url = '/findComplaintCoped'
                    break
                default:
                    break;
            }

            try {
                const res = await this.$http.post(url, {
                    pageNum: this.current_page,
                    pageSize: this.pageSize
                });
                console.log(res.data)
                if (res.data.code === 2000) {
                    this.total = res.data.data.size
                    this.table_data = res.data.data.information
                } else {
                    this.$message.error('出错啦')
                }
            } catch (error) { }
        },


        // 获取子组件传来的row_id
        row_id(val) {
            this.row_index = val
            this.add_form = this.table_data.find(item => item.id === val)
        },
    },

}
</script>

<style lang="less" scoped>
.table_box {
    width: 100%;
    height: 100%;
}

.el-input {
    display: inline-block;
}
</style>